#include "logger.h"

void init_logger(const std::string& log_path, const std::string& log_name) {
    auto console = std::make_shared<ConsoleChannel>();
    auto file = std::make_shared<FileChannel>(log_name, log_path);
    file->setMaxDay(10);
    file->setFileMaxSize(100);
    file->setFileMaxCount(15);

    Logger::Instance().add(console);
    Logger::Instance().add(file);
    Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
}

int main() {
    init_logger("./", "delog");

    InfoL << "测试std::cout风格打印：";

    // 这是ostream原生支持的数据类型
    TraceL << "int" << (int)1 << std::endl;
    DebugL << "short:" << (short)2 << std::endl;
    InfoL << "float:" << (float)3.12345678 << std::endl;
    WarnL << "double:" << (double)4.12345678901234567 << std::endl;
    ErrorL << "void *:" << (void*)0x12345678 << std::endl;
    // 根据RAII的原理，此处不需要输入 endl，也会在被函数栈pop时打印log
    ErrorL << "without endl!";

    PrintI("测试printf风格打印：");
    PrintT("this is a %s test:%d", "printf trace", 124);
    PrintD("this is a %s test:%p", "printf debug", (void*)124);
    PrintI("this is a %s test:%c", "printf info", 'a');
    PrintW("this is a %s test:%X", "printf warn", 0x7F);
    PrintE("this is a %s test:%x", "printf err", 0xab);

    LogI("测试可变长度模板样式打印：");
    LogT(1, "+", "2", '=', 3);
    LogD(1, "+", "2", '=', 3);
    LogI(1, "+", "2", '=', 3);
    LogW(1, "+", "2", '=', 3);
    LogE(1, "+", "2", '=', 3);

    for (int i = 0; i < 2; ++i) {
        DebugL << "this is a repeat 2 times log";
        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    for (int i = 0; i < 3; ++i) {
        DebugL << "this is a repeat 3 times log";
        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    for (int i = 0; i < 100; ++i) {
        DebugL << "this is a repeat 100 log";
        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    InfoL << "done!";
    return 0;
}